package components.contorls.superClass
{
    import components.core.UIComponent;
    import components.events.EnterInputCompleteEvent;
    import components.utils.EventListenerUtil;
    
    import flash.events.Event;
    import flash.events.MouseEvent;

    /**
     *输入界面
     * @author zn
     *
     */
    public class BaseInputComponent extends UIComponent
    {

        public function BaseInputComponent()
        {
            super();
			
			EventListenerUtil.addEventListener(closeBtn,MouseEvent.CLICK,closeButton_clickHandler);
			EventListenerUtil.addEventListener(confirmBtn,MouseEvent.CLICK,confirmBtn_clickHandler);
			EventListenerUtil.addEventListener(nameTextInput,Event.CHANGE,textInput_changeHandler);
        }
		
		public function get nameTextInput():BaseTextInput
		{
			return getChildByName("nameTextInputSkin") as BaseTextInput;
		}
		
		public function get closeBtn():BaseButton
		{
			return getChildByName("closeBtnSkin") as BaseButton;
		}
		
		public function get confirmBtn():BaseButton
		{
			return getChildByName("confirmBtnSkin") as BaseButton;
		}
		
		protected function textInput_changeHandler(event:Event):void
		{
			validateConfirmBtn();
		}

		private function validateConfirmBtn():void
		{
			if(nameTextInput.text!="" && nameTextInput.text!=null)
				confirmBtn.enabled=true;
			else
				confirmBtn.enabled=false;
		}


		protected override function frameConstructedHandler(event:Event):void
		{
			super.frameConstructedHandler(event);
			validateConfirmBtn();
		}

		
		protected function confirmBtn_clickHandler(event:MouseEvent):void
		{
			dispatchEvent(new EnterInputCompleteEvent(nameTextInput.text));
			nameTextInput.text="";
			validateConfirmBtn();
			closeButton_clickHandler(null);
		}
		
		protected function closeButton_clickHandler(event:MouseEvent):void
		{
			dispatchEvent(new Event(Event.CLOSE));
		}
	}
}